import moment from 'moment'
import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'

function examine(status, name) {
  let data = []
  if (name === 'allowanceMar') {
    data = [
      {
        field: 'auditStateStr',
        title: '审批状态',
        minWidth: 100
      },
      {
        field: 'nextChecker',
        title: '当前审批节点',
        minWidth: 160
      }
    ]
  } else {
    if (status != '0') {
      data = [
        {
          field: 'auditName',
          title: '审批人',
          minWidth: 100
        },
        {
          title: '审批日期',
          minWidth: 120,
          cell: {
            value: (row) => moment(row.auditTime).format('YYYY-MM-DD'),
            text: {}
          }
        }
      ]
    }
    if (status == '2') {
      data.push({
        field: 'auditReason',
        title: '驳回原因',
        minWidth: 150
      })
    }
  }
  return data
}

function options(status, name, _this) {
  return [
    {
      type: 'index',
      title: '序号',
      minWidth: 50
    },
    {
      field: 'orgName',
      title: '所属组织',
      visible: name != 'caseAllowanceApprove',
      minWidth: 160
    },
    {
      field: 'housesName',
      title: '案场名称',
      visible: name != 'caseAllowanceApprove',
      minWidth: 160
    },
    {
      field: 'auditData.allowanceName',
      title: '津贴名称',
      minWidth: 100
    },
    {
      field: 'auditData.allowanceType',
      title: '津贴类型',
      minWidth: 120
    },
    {
      field: 'auditData.allowanceMoney',
      title: '津贴总额（元）',
      minWidth: 150
    },
    {
      field: 'auditData.allowanceMonth',
      title: '发放月份',
      minWidth: 100
    },
    {
      field: 'submitName',
      title: '提交人',
      minWidth: 120
    },
    {
      field: 'submitTime',
      title: '提交日期',
      minWidth: 140
    },

    ...examine(status, name),
    {
      field: 'handles',
      title: '操作',
      minWidth: 140,
      fixed: 'right',
      cell: () => {
        return {
          btn: [
            {
              title: '查看',
              event: 'onDetail'
            },
            {
              title: '流程信息',
              event: 'onFlow',
              visible: name === 'allowanceMar'
            },
            {
              title: '审批',
              event: 'onAudit',
              code: name == 'allowanceApprove' ? '0206050501' : '0109080100',
              visible: name !== 'allowanceMar' && status == '0'
            }
          ]
        }
      }
    }
  ]
}

export default {
  options
}
